package org.outlook.test.ui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JLabelWithBg extends JLabel {
	private static final long serialVersionUID = 1L;
	
	Image image;

	public JLabelWithBg(String text, Icon icon, int horizontalAlignment) {
		super(text, icon, horizontalAlignment);
	}

	@Override
	public void paint(Graphics g) {
		super.paintComponent(g);
		if(image != null) {
			Dimension size = getSize();
//			int iconWidth = icon.getIconWidth();
//			int iconHeight = icon.getIconHeight();
			
			g.drawImage(image, 0,0/*(int)(size.getWidth()-iconHeight)/2, (int)(size.getHeight()-iconHeight)/2*/, null, this);
		}
	}

	public void setImage(Image icon) {
		this.image = icon;
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
//		JLabel label = new JLabel("text", new ImageIcon("D:/pulsar/workspace/emoticons/star.png"), JLabel.LEFT);
//		Image image = Toolkit.getDefaultToolkit().getImage("D:/pulsar/workspace/emoticons/Male.jpg");
//        Icon icon = new ImageIcon(image);
//		label.setIcon(icon);
		JLabelWithBg label = new JLabelWithBg("text", new ImageIcon("D:/pulsar/workspace/emoticons/star.png"), JLabel.LEFT);
//		label.setText("text");
//		label.setIcon(new ImageIcon("D:/pulsar/workspace/emoticons/star.png"));
//		label.setHorizontalAlignment(JLabel.LEFT);
		label.setImage(Toolkit.getDefaultToolkit().getImage("D:/pulsar/workspace/emoticons/Male.jpg"));
		
		frame.add(label);
		frame.setVisible(true);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
